<template>
  <div>
    <Row>
      <Card>
        <div slot="extra">
          <Button type="primary" style="position: relative;right: 15px;" @click="subForm" :loading="modal.loading">保存
          </Button>
          <Button type="primary" @click="backFn">
            <Icon type="arrow-return-left"></Icon>
            返回
          </Button>
        </div>
        <p slot="title">
          <Icon type="navicon-round"></Icon>
          [{{school.name}}] 简介管理
        </p>
        <div ref="editor" style="height: 450px;"></div>
        <div style="height: 300px;display: none">
          <PicUpload ref="picUpload" accept="image/*" @get-file="getUploadFile" :multiple="false"
                     delImgPath="kindergarten/logo">

          </PicUpload>
        </div>
      </Card>
    </Row>
  </div>
</template>

<script>
  import E from 'wangeditor'
  import PicUpload from "@/components/views/upload/Upload"
  import API from "@/api/api";

  export default {
    name: "SchoolBrief",
    components: {PicUpload},
    data() {
      return {
        editor: null,
        config: {
          pasteText: true,
          fontsizes: {
            1: '10px',
            2: '13px',
            3: '16px',
            4: '19px',
            5: '22px',
            6: '25px',
            7: '28px'
          },
          familys: ['宋体', '黑体', '楷体', '微软雅黑',
            'Arial', 'Verdana', 'Georgia'],
          menus: [
            'bold', // 粗体
            'fontSize', // 字号
            'fontName', // 字体
            'italic', // 斜体
            'underline', // 下划线
            'strikeThrough', // 删除线
            'foreColor', // 文字颜色
            'backColor', // 背景颜色
            'justify', // 对齐方式
            'undo', // 撤销
            'redo' // 重复
          ]
        },
        modal: {
          loading: false,
        },
        school: {
          name: '',
          id: '',
          brief: ''
        },
        dataHeight: 0,
        conHeight: 0
      }
    },
    methods: {
      getInfo() {
        API.fetchKindergartenBriefAndImage(this.school.id).then(resp => {
          let brief = resp.data.brief;
          let album = resp.data.album;
          this.editor.txt.text(brief);
        })
      },
      getUploadFile(fileList, newFile) {

      },
      setHeight() {
        let mHeight = $('.container').outerHeight();
        let hHeight = $('.ivu-card-head').outerHeight();
        let fHeight = $('#footer').outerHeight();
        let cHeight = mHeight - hHeight - fHeight;
        this.dataHeight = cHeight - 40;
        this.conHeight = cHeight - 175;
      },
      subForm() {
        let briefTxt = this.editor.txt.text();
        if (!briefTxt) {
          this.$Message.warning('请输入简介内容');
          return;
        }
        this.school.brief = this.editor.txt.html();
        API.updateKindergarten(this.school).then(resp => {
          this.getInfo();
        })
      },
      backFn() {
        this.$router.push({
          path: '/kindergarten'
        })
      }
    },
    created() {
    },
    mounted() {
      this.school.id = this.$route.query.kId;
      this.school.name = this.$route.query.n;
      this.editor = new E(this.$refs.editor)
      this.editor.customConfig = this.config;
      this.editor.create();
      this.getInfo();
    }
  }
</script>

<style scoped>

</style>
